package com.lagou.mrsort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SortMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {

    /*
        map阶段，输入key为文本偏移量，value为一个数字
        输出key为当前行序号，value为NullWritable.get()
     */

    IntWritable k = new IntWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        // 读取一行文本，并转为IntWritable类型
        Integer integer = Integer.parseInt(value.toString());

        //输出文本数据
        k.set(integer);
        context.write(k, NullWritable.get());
    }
}
